package com.yunxi.service.app.dubbo;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yunxi.baseDataToHub.pojo.app.*;
import com.yunxi.baseDataToHub.service.app.AppDubboService;
import com.yunxi.core.base.Constant;
import com.yunxi.core.util.HttpUtil;
import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.model.eai.EaiLog;
import com.yunxi.rocketmq.producer.EaiLogsProducer;
import com.yunxi.service.eai.EaiLogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2019/6/1.
 */
public class AppDubboServiceImpl implements AppDubboService {
    protected static final Logger LOGGER = LoggerFactory.getLogger(AppDubboServiceImpl.class);
    @Autowired
    private EaiLogsProducer eaiLogsProducer;
    @Value("${esb.switch}")
    private String esbSwitch;
    @Value("${APP.AUDIT.URL}")
    private String APP_AUDIT__URL;
    @Value("${APP.URL}")
    private String APP_URL;
    @Value("${APP.VEHICLE.URL}")
    private String APP_VEHICLE_URL;
    @Autowired
    @Qualifier("eaiLogServiceImpl")
    EaiLogService eaiLogService;
    @Override
    public ApiResult auditAppLittleOrder(AppLittleOrderAuditVO appLittleOrderAuditVO) {
        String appLittleOrderAudit = JSONObject.toJSONString(appLittleOrderAuditVO);
        ApiResult apiResult = null;
        EaiLog eaiLog = new EaiLog();
        eaiLog.setPmsEaiContent(appLittleOrderAudit);
        eaiLog.setRequestSendTime(new Date());
        eaiLog.setFlowDesc("PMS系统发送小订审核数据给APP系统");
        eaiLog.setSourceSystem(Constant.PMS);
        eaiLog.setServiceName(Constant.APP_LITTLE_ORDER_AUDIT);
        if (esbSwitch.equals("false")) {
            eaiLog.setCreateDate(new Date());
            eaiLogService.saveOrUpdate(eaiLog);
            return ResponseUtil.ok();
        }
        try {
            Map map = HttpUtil.sendPost(appLittleOrderAudit, Constant.APP_LITTLE_ORDER_AUDIT, Constant.PMS, APP_AUDIT__URL);
            eaiLog.setRequestId(String.valueOf(map.get("requestId")));
            eaiLog.setResponseReceiveTime(new Date());
            eaiLog.setEsbResultContent(JSONObject.toJSONString(map));
            eaiLog.setUrl(APP_AUDIT__URL);
            Object object = map.get("header");
            JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(object));
            String statusFlag = String.valueOf(jsonObject.get("statusFlag"));
            if (statusFlag.equals("0")) {//这里只对ESB的处理状态做判断
                //处理失败，更状态位失败
                eaiLog.setDisposeStatus(2);
                apiResult = ResponseUtil.fail(Constant.APP_R_CODE_FAIL,"["+Constant.APP_LITTLE_ORDER_AUDIT+"]");
            } else {
                //将返回的数据返给PMS
                JSONObject jsonResponse = JSONObject.parseObject(String.valueOf(map.get("response")));
                if (Integer.parseInt(String.valueOf(jsonResponse.get("code"))) != 200) {
                    //处理失败，更状态位失败
                    eaiLog.setDisposeStatus(2);
                    apiResult = ResponseUtil.fail(Constant.APP_R_CODE_ERR,"["+Constant.APP_LITTLE_ORDER_AUDIT+"]"+jsonResponse.get("message"));
                } else {
                    apiResult = ResponseUtil.ok(map.get("response"));
                }
            }
        } catch (Exception e) {
            //处理失败，更状态位失败
            eaiLog.setDisposeStatus(2);
            LOGGER.error(e.getMessage(), e);
            LOGGER.error("调用ESB系统失败===========");
            apiResult = ResponseUtil.fail(Constant.APP_R_CODE_EXP,"["+Constant.APP_LITTLE_ORDER_AUDIT+"]");
        }
        //  Message message = new Message(rocketConfig.getEaiLogTopic(), "eaiLog",(JSONObject.toJSONString(eaiLog)).getBytes() );
        try {
            //   SendResult send = eaiLogProducer.getProducer().send(message);
            eaiLogsProducer.sendMessage(JSONObject.toJSONString(eaiLog));
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
            apiResult=ResponseUtil.fail(Constant.APP_R_CODE_EAI,"["+Constant.APP_LITTLE_ORDER_AUDIT+"]");
        }
        return apiResult;
    }

    @Override
    public ApiResult sendOrderStatusPMS2APP(OrderStatusVO order) {
        String orderStatus = JSONObject.toJSONString(order);
        ApiResult apiResult = null;
        EaiLog eaiLog = new EaiLog();
        eaiLog.setPmsEaiContent(orderStatus);
        eaiLog.setPmsEaiText(orderStatus);
        eaiLog.setRequestSendTime(new Date());
        eaiLog.setFlowDesc("PMS系统发送车辆状态数据给APP系统");
        eaiLog.setSourceSystem(Constant.PMS);
        eaiLog.setServiceName(Constant.PMS_ORDER_STATUS);
        if (esbSwitch.equals("false")) {
            eaiLog.setCreateDate(new Date());
            eaiLogService.saveOrUpdate(eaiLog);
            return ResponseUtil.ok();
        }
        try {
            Map map = HttpUtil.sendPost(orderStatus, Constant.PMS_ORDER_STATUS, Constant.PMS, APP_URL);
            eaiLog.setRequestId(String.valueOf(map.get("requestId")));
            eaiLog.setResponseReceiveTime(new Date());
            eaiLog.setEsbResultContent(JSONObject.toJSONString(map));
            eaiLog.setUrl(APP_URL);
            Object object = map.get("header");
            JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(object));
            String statusFlag = String.valueOf(jsonObject.get("statusFlag"));
            if (statusFlag.equals("0")) {//这里只对ESB的处理状态做判断
                //处理失败，更状态位失败
                eaiLog.setDisposeStatus(2);
                apiResult=ResponseUtil.fail(Constant.APP_R_CODE_FAIL,"["+Constant.PMS_ORDER_STATUS+"]");
            } else {
                //将返回的数据返给PMS
                JSONObject jsonResponse = JSONObject.parseObject(String.valueOf(map.get("response")));
                if (Integer.parseInt(String.valueOf(jsonResponse.get("code"))) != 200) {
                    //处理失败，更状态位失败
                    eaiLog.setDisposeStatus(2);
                    apiResult=ResponseUtil.fail(Constant.APP_R_CODE_ERR,"["+Constant.PMS_ORDER_STATUS+"]"+jsonResponse.get("message"));
                } else {
                    apiResult = ResponseUtil.ok(map.get("response"));
                }
            }
        } catch (Exception e) {
            //处理失败，更状态位失败
            eaiLog.setDisposeStatus(2);
            LOGGER.error(e.getMessage(), e);
            LOGGER.error("调用ESB系统失败===========");
            apiResult=ResponseUtil.fail(Constant.APP_R_CODE_EXP,"["+Constant.PMS_ORDER_STATUS+"]");
        }
        try {
            eaiLogsProducer.sendMessage(JSONObject.toJSONString(eaiLog));
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
            apiResult=ResponseUtil.fail(Constant.APP_R_CODE_EAI,"["+Constant.PMS_ORDER_STATUS+"]");
        }
        return apiResult;
    }

    @Override
    public ApiResult sendVehiclePackagePricePMS2APP(List<VehiclePackagePriceVO> order) {
        String orderStatus = JSONObject.toJSONString(order);
        ApiResult apiResult = null;
        EaiLog eaiLog = new EaiLog();
        eaiLog.setPmsEaiContent(orderStatus);
        eaiLog.setPmsEaiText(orderStatus);
        eaiLog.setRequestSendTime(new Date());
        eaiLog.setServiceName(eaiLog.getServiceName());
        eaiLog.setFlowDesc("PMS系统发送选装包价格给APP系统");
        eaiLog.setSourceSystem(Constant.PMS);
        if (order.size() > 0) {
            if (order.get(0).getOptionType() == 1) {
                eaiLog.setServiceName(Constant.PMS_SAVE_VEHICLE_PACKAGE_PRICE);
            } else {
                eaiLog.setServiceName(Constant.PMS_UPDATE_VEHICLE_PACKAGE_PRICE);
            }
        }

        if (esbSwitch.equals("false")) {
            eaiLog.setCreateDate(new Date());
            eaiLogService.saveOrUpdate(eaiLog);
            return ResponseUtil.ok();
        }
        try {
            Map map = null;
            if (order.size() > 0) {
                if (order.get(0).getOptionType() == 1) {
                    map = HttpUtil.sendPost(orderStatus, Constant.PMS_SAVE_VEHICLE_PACKAGE_PRICE, Constant.PMS, APP_URL);
                } else {
                    map = HttpUtil.sendPost(orderStatus, Constant.PMS_UPDATE_VEHICLE_PACKAGE_PRICE, Constant.PMS, APP_URL);

                }
            }
            eaiLog.setRequestId(String.valueOf(map.get("requestId")));
            eaiLog.setResponseReceiveTime(new Date());
            eaiLog.setEsbResultContent(JSONObject.toJSONString(map));
            eaiLog.setUrl(APP_URL);
            Object object = map.get("header");
            JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(object));
            String statusFlag = String.valueOf(jsonObject.get("statusFlag"));
            if (statusFlag.equals("0")) {//这里只对ESB的处理状态做判断
                //处理失败，更状态位失败
                eaiLog.setDisposeStatus(2);
                apiResult = ResponseUtil.fail(Constant.APP_R_CODE_FAIL,"["+Constant.PMS_UPDATE_VEHICLE_PACKAGE_PRICE+"]");
            } else {
                //将返回的数据返给PMS
                JSONObject jsonResponse = JSONObject.parseObject(String.valueOf(map.get("response")));
                if (Integer.parseInt(String.valueOf(jsonResponse.get("code"))) != 200) {
                    //处理失败，更状态位失败
                    eaiLog.setDisposeStatus(2);
                    apiResult = ResponseUtil.fail(Constant.APP_R_CODE_ERR,"["+Constant.PMS_UPDATE_VEHICLE_PACKAGE_PRICE+"]"+jsonResponse.get("message"));
                } else {
                    apiResult = ResponseUtil.ok(map.get("response"));
                }
            }
        } catch (Exception e) {
            //处理失败，更状态位失败
            eaiLog.setDisposeStatus(2);
            LOGGER.error(e.getMessage(), e);
            LOGGER.error("调用ESB系统失败===========");
            apiResult = ResponseUtil.fail(Constant.APP_R_CODE_EXP,"["+Constant.PMS_UPDATE_VEHICLE_PACKAGE_PRICE+"]");
        }
        try {
            eaiLogsProducer.sendMessage(JSONObject.toJSONString(eaiLog));
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
            apiResult=ResponseUtil.fail(Constant.APP_R_CODE_EAI,"["+Constant.PMS_UPDATE_VEHICLE_PACKAGE_PRICE+"]");
        }
        return apiResult;
    }

    @Override
    public ApiResult sendVehiclePackagePMS2APP(List<VehiclePackageConfigVO> order) {
        String orderStatus = JSONObject.toJSONString(order);
        ApiResult apiResult = null;
        EaiLog eaiLog = new EaiLog();
        eaiLog.setPmsEaiContent(orderStatus);
        eaiLog.setPmsEaiText(orderStatus);
        eaiLog.setRequestSendTime(new Date());
        eaiLog.setFlowDesc("PMS系统发送内外饰颜色配置给APP系统");
        eaiLog.setSourceSystem(Constant.PMS);
        if (order.size() > 0) {
            if (order.get(0).getOptionType() == 1) {
                eaiLog.setServiceName(Constant.PMS_SAVE_VEHICLE_PACKAGE_CONFIG);
            } else {
                eaiLog.setServiceName(Constant.PMS_UPDATE_VEHICLE_PACKAGE_CONFIG);
            }
        }
        if (esbSwitch.equals("false")) {
            eaiLog.setCreateDate(new Date());
            eaiLogService.saveOrUpdate(eaiLog);
            return ResponseUtil.ok();
        }
        try {
            Map map = null;
            if (order.size() > 0) {
                if (order.get(0).getOptionType() == 1) {
                    map = HttpUtil.sendPost(orderStatus, Constant.PMS_SAVE_VEHICLE_PACKAGE_CONFIG, Constant.PMS, APP_URL);
                } else {
                    map = HttpUtil.sendPost(orderStatus, Constant.PMS_UPDATE_VEHICLE_PACKAGE_CONFIG, Constant.PMS, APP_URL);

                }
            }
            eaiLog.setRequestId(String.valueOf(map.get("requestId")));
            eaiLog.setResponseReceiveTime(new Date());
            eaiLog.setEsbResultContent(JSONObject.toJSONString(map));
            eaiLog.setUrl(APP_URL);
            Object object = map.get("header");
            JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(object));
            String statusFlag = String.valueOf(jsonObject.get("statusFlag"));
            if (statusFlag.equals("0")) {//这里只对ESB的处理状态做判断
                //处理失败，更状态位失败
                eaiLog.setDisposeStatus(2);
                apiResult = ResponseUtil.fail(Constant.APP_R_CODE_FAIL,"["+Constant.PMS_UPDATE_VEHICLE_PACKAGE_CONFIG+"]");
            } else {
                //将返回的数据返给PMS
                JSONObject jsonResponse = JSONObject.parseObject(String.valueOf(map.get("response")));
                if (Integer.parseInt(String.valueOf(jsonResponse.get("code"))) != 200) {
                    //处理失败，更状态位失败
                    eaiLog.setDisposeStatus(2);
                    apiResult = ResponseUtil.fail(Constant.APP_R_CODE_ERR,"["+Constant.PMS_UPDATE_VEHICLE_PACKAGE_CONFIG+"]"+jsonResponse.get("message"));
                } else {
                    apiResult = ResponseUtil.ok(map.get("response"));
                }
            }
        } catch (Exception e) {
            //处理失败，更状态位失败
            eaiLog.setDisposeStatus(2);
            LOGGER.error(e.getMessage(), e);
            LOGGER.error("调用ESB系统失败===========");
            apiResult = ResponseUtil.fail(Constant.APP_R_CODE_EXP,"["+Constant.PMS_UPDATE_VEHICLE_PACKAGE_CONFIG+"]");
        }
        try {
            eaiLogsProducer.sendMessage(JSONObject.toJSONString(eaiLog));
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
            apiResult=ResponseUtil.fail(Constant.APP_R_CODE_EAI,"["+Constant.PMS_UPDATE_VEHICLE_PACKAGE_CONFIG+"]");
        }
        return apiResult;
    }

    @Override
    public ApiResult sendVehicleRetailPricePMS2APP(VehicleRetailPriceVO order) {
        String orderStatus = JSONObject.toJSONString(order);
        ApiResult apiResult = null;
        EaiLog eaiLog = new EaiLog();
        eaiLog.setPmsEaiContent(orderStatus);
        eaiLog.setPmsEaiText(orderStatus);
        eaiLog.setRequestSendTime(new Date());
        eaiLog.setFlowDesc("PMS系统发送车型价格给APP系统");
        eaiLog.setSourceSystem(Constant.PMS);
        if (order.getOptionType() == 1) {
            eaiLog.setServiceName(Constant.PMS_SAVE_VEHICLE_RETAIL_PRICE);
        } else {
            eaiLog.setServiceName(Constant.PMS_UPDATE_VEHICLE_RETAIL_PRICE);
        }
        if (esbSwitch.equals("false")) {
            eaiLog.setCreateDate(new Date());
            eaiLogService.saveOrUpdate(eaiLog);
            return ResponseUtil.ok("未开启ESB，不会执行app同步");
        }
        try {
            Map map = null;
            if (order.getOptionType() == 1) {
                map = HttpUtil.sendPost(orderStatus, Constant.PMS_SAVE_VEHICLE_RETAIL_PRICE, Constant.PMS, APP_VEHICLE_URL);
            } else {
                map = HttpUtil.sendPost(orderStatus, Constant.PMS_UPDATE_VEHICLE_RETAIL_PRICE, Constant.PMS, APP_VEHICLE_URL);

            }
            eaiLog.setRequestId(String.valueOf(map.get("requestId")));
            eaiLog.setResponseReceiveTime(new Date());
            eaiLog.setEsbResultContent(JSONObject.toJSONString(map));
            eaiLog.setUrl(APP_VEHICLE_URL);
            Object object = map.get("header");
            JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(object));
            String statusFlag = String.valueOf(jsonObject.get("statusFlag"));
            if (esbSwitch.equals("false")) {
                return ResponseUtil.ok("未开启ESB，不会执行app同步");
            }
            if (statusFlag.equals("0")) {//这里只对ESB的处理状态做判断
                //处理失败，更状态位失败
                eaiLog.setDisposeStatus(2);
                apiResult = ResponseUtil.fail(Constant.APP_R_CODE_FAIL,"["+Constant.PMS_UPDATE_VEHICLE_RETAIL_PRICE+"]");
            } else {
                //将返回的数据返给PMS
                JSONObject jsonResponse = JSONObject.parseObject(String.valueOf(map.get("response")));
                if (Integer.parseInt(String.valueOf(jsonResponse.get("code"))) != 200) {
                    //处理失败，更状态位失败
                    eaiLog.setDisposeStatus(2);
                    apiResult =ResponseUtil.fail(Constant.APP_R_CODE_ERR,"["+Constant.PMS_UPDATE_VEHICLE_RETAIL_PRICE+"]"+jsonResponse.get("message"));
                } else {
                    apiResult = ResponseUtil.ok(map.get("response"));
                }
            }
        } catch (Exception e) {
            //处理失败，更状态位失败
            eaiLog.setDisposeStatus(2);
            LOGGER.error(e.getMessage(), e);
            LOGGER.error("调用ESB系统失败===========");
            apiResult = ResponseUtil.fail(Constant.APP_R_CODE_EXP,"["+Constant.PMS_UPDATE_VEHICLE_RETAIL_PRICE+"]");
        }
        try {
            eaiLogsProducer.sendMessage(JSONObject.toJSONString(eaiLog));
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
            apiResult=ResponseUtil.fail(Constant.APP_R_CODE_EAI,"["+Constant.PMS_UPDATE_VEHICLE_RETAIL_PRICE+"]");
        }
        return apiResult;
    }

    @Override
    public ApiResult sendCreditInvestigationAuditPMS2APP(CreditInvestigationAuditVO order) {
        String orderStatus = JSONObject.toJSONString(order);
        ApiResult apiResult = null;
        EaiLog eaiLog = new EaiLog();
        eaiLog.setPmsEaiContent(orderStatus);
        eaiLog.setPmsEaiText(orderStatus);
        eaiLog.setRequestSendTime(new Date());
        eaiLog.setFlowDesc("PMS系统发送征信审核信息给APP系统");
        eaiLog.setSourceSystem(Constant.PMS);
        eaiLog.setServiceName(Constant.PMS_APP_CREDIT_INVESTIGATION_AUDIT);
        if (esbSwitch.equals("false")) {
            eaiLog.setCreateDate(new Date());
            eaiLogService.saveOrUpdate(eaiLog);
            return ResponseUtil.ok();
        }
        try {
            Map map = null;
            map = HttpUtil.sendPost(orderStatus, Constant.PMS_APP_CREDIT_INVESTIGATION_AUDIT, Constant.PMS, APP_URL);
            eaiLog.setRequestId(String.valueOf(map.get("requestId")));
            eaiLog.setResponseReceiveTime(new Date());
            eaiLog.setEsbResultContent(JSONObject.toJSONString(map));
            eaiLog.setUrl(APP_URL);
            Object object = map.get("header");
            JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(object));
            String statusFlag = String.valueOf(jsonObject.get("statusFlag"));
            if (statusFlag.equals("0")) {//这里只对ESB的处理状态做判断
                //处理失败，更状态位失败
                eaiLog.setDisposeStatus(2);
                apiResult=ResponseUtil.fail(Constant.APP_R_CODE_FAIL,"["+Constant.PMS_APP_CREDIT_INVESTIGATION_AUDIT+"]");
            } else {
                //将返回的数据返给PMS
                JSONObject jsonResponse = JSONObject.parseObject(String.valueOf(map.get("response")));
                if (Integer.parseInt(String.valueOf(jsonResponse.get("code"))) != 200) {
                    //处理失败，更状态位失败
                    eaiLog.setDisposeStatus(2);
                    apiResult=ResponseUtil.fail(Constant.APP_R_CODE_ERR,"["+Constant.PMS_APP_CREDIT_INVESTIGATION_AUDIT+"]"+jsonResponse.get("message"));
                } else {
                    apiResult = ResponseUtil.ok(map.get("response"));
                }
            }
        } catch (Exception e) {
            //处理失败，更状态位失败
            eaiLog.setDisposeStatus(2);
            LOGGER.error(e.getMessage(), e);
            LOGGER.error("调用ESB系统失败===========");
            apiResult = ResponseUtil.fail(Constant.APP_R_CODE_EXP,"["+Constant.PMS_APP_CREDIT_INVESTIGATION_AUDIT+"]");
        }
        try {
            eaiLogsProducer.sendMessage(JSONObject.toJSONString(eaiLog));
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
            apiResult=ResponseUtil.fail(Constant.APP_R_CODE_EAI,"["+Constant.PMS_APP_CREDIT_INVESTIGATION_AUDIT+"]");
        }
        return apiResult;
    }

    /**
     * PMS=>APP 金融方案审核结果返回
     * @param financeAuditVO
     * @return
     */
    @Override
    public ApiResult sendFinanceAuditPMS2APP(FinanceAuditVO financeAuditVO) {
        String info = JSONObject.toJSONString(financeAuditVO);
        ApiResult apiResult = null;
        EaiLog eaiLog = new EaiLog();
        eaiLog.setPmsEaiContent(info);
        eaiLog.setPmsEaiText(info);
        eaiLog.setRequestSendTime(new Date());
        eaiLog.setFlowDesc("PMS系统发送金融方案审核结果给APP系统");
        eaiLog.setSourceSystem(Constant.PMS);
        eaiLog.setServiceName(Constant.PMS_APP_FINANCE_AUDIT);
        if (esbSwitch.equals("false")) {
            eaiLog.setCreateDate(new Date());
            eaiLogService.saveOrUpdate(eaiLog);
            return ResponseUtil.ok();
        }
        try{
            Map map = HttpUtil.sendPost(info, Constant.PMS_APP_FINANCE_AUDIT, Constant.PMS, APP_URL);
            eaiLog.setRequestId(String.valueOf(map.get("requestId")));
            eaiLog.setResponseReceiveTime(new Date());
            eaiLog.setEsbResultContent(JSONObject.toJSONString(map));
            eaiLog.setUrl(APP_URL);
            Object object = map.get("header");
            JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(object));
            String statusFlag = String.valueOf(jsonObject.get("statusFlag"));
            if (statusFlag.equals("0")) {//这里只对ESB的处理状态做判断
                //处理失败，更状态位失败
                eaiLog.setDisposeStatus(2);
                apiResult=ResponseUtil.fail(Constant.APP_R_CODE_FAIL,"["+Constant.PMS_APP_FINANCE_AUDIT+"]");
            } else {
                //将返回的数据返给PMS
                JSONObject jsonResponse = JSONObject.parseObject(String.valueOf(map.get("response")));
                if (Integer.parseInt(String.valueOf(jsonResponse.get("code"))) != 200) {
                    //处理失败，更状态位失败
                    eaiLog.setDisposeStatus(2);
                    apiResult=ResponseUtil.fail(Constant.APP_R_CODE_ERR,"["+Constant.PMS_APP_FINANCE_AUDIT+"]"+jsonResponse.get("message"));
                } else {
                    apiResult = ResponseUtil.ok(map.get("response"));
                }
            }
        }
        catch (Exception e){
            //处理失败，更状态位失败
            eaiLog.setDisposeStatus(2);
            LOGGER.error(e.getMessage(), e);
            LOGGER.error("调用ESB系统失败===========");
            apiResult = ResponseUtil.fail(Constant.APP_R_CODE_EXP,"["+Constant.PMS_APP_FINANCE_AUDIT+"]");
        }
        try {
            eaiLogsProducer.sendMessage(JSONObject.toJSONString(eaiLog));
        } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
            apiResult=ResponseUtil.fail(Constant.APP_R_CODE_EAI,"["+Constant.PMS_APP_FINANCE_AUDIT+"]");
        }
        return apiResult;
    }
}
